<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>全球新冠状病毒确诊情况调查表</title>
    <style text="text/css">
        body{
            width: 1300px;
            background-color: black;
        }
        td,th{
            height: 40px;
            width: 300px;
            align-content: center;
        }
        td{
            text-align: center;
        }
        #eat{
            float: right;
            margin-right: 20px;
            margin-top: 150px;
        }
        h1{
            float: left;
            margin-top: 50px;
            margin-left: 50px;
        }
        a{
            font-size: 20px;
            text-decoration:none;
        }
        * {
            margin: 0;
            padding: 0;
        }

        ul {
            list-style: none;
        }

        #eat > a {
            display: block;
            height: 20px;
            width: 70px;
            color: #000;
            line-height: 30px;
            text-align: center;

        }
        #eat ul {
            display: none;
            position: absolute;
        }
    </style>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
</head>
<body>
<div id="page" align="center">
    <div style="background-color: deepskyblue;width: 910px;height: 200px;">
        <h1>全球新冠状病毒确诊情况</h1>
        <span style="float:right;font-size: 35px;margin-top: 50px;margin-right: 80px;">合计：0</span>
        <div id="eat">
            <a href="javascript:">global</a>

            <ul class="ul">
                <li><a href="javascript:">China</a></li>
                <li><a href="javascript:void(0);">Australia</a></li>
                <li><a href="javascript:void(0);">Canada</a></li>
                <li><a href="javascript:void(0);">France</a></li>
                <li><a href="javascript:void(0);">Netherlands</a></li>
                <li><a href="javascript:void(0);">United Kingdom</a></li>
            </ul>
        </div>
    </div>
    <table style="background-color: white;">
        <tr>
            <th>省份/州</th>
            <th>国家</th>
            <th>确诊人数</th>
        </tr>
        <tbody id="tab">
        </tbody>
    </table>
</div>
<script type="text/javascript">
    var a=document.querySelector('a');
    $(function() {

        $("a").on("click",function () {
            var args=$(this).text();
            alert(args+"区域调查情况");
            var al=a.text;
            a.text=args;
            $(this).text(al);
            $.ajax({
                url:"http://localhost:8080/fan?args="+args,
                type:"GET",
                dataType:"json",
                success:function (data) {
                    //location.reload();
                    $('#tab').html("");
                    var num=0;
                    for(var i=0;i<data.length;i++){
                        //console.log(parseInt(data[i].allNum));
                        //console.log(num);
                        num=num+parseInt(data[i].allNum);
                        $("#tab").append("<tr><td>"+data[i].state+"</td><td>"+data[i].country+"</td><td>"+data[i].allNum+"</td></tr>");
                    }
                    $("span").text("总计："+num);
                },
                error:function () {
                    alert("出现错误！！！！");
                }
            })
        })

        var $li = $("#eat");

        $li.mouseenter(function () {
            $(this).children("ul").show();
        });

        $li.mouseleave(function () {
            $(this).children("ul").hide();
        });
    })
</script>
</body>

</html>